<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>号码绑定</title>
	<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
	<meta content="yes" name="apple-mobile-web-app-capable" />
	<meta content="black" name="apple-mobile-web-app-status-bar-style" />
	<meta content="telephone=no" name="format-detection" />
	<link href="style.css" rel="stylesheet" type="text/css" />
	<script src="./jquery.min.js"></script>
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <script src="/zweixin/resource/layer.mobile-v2.0/layer_mobile/layer.js"></script>
	<!-- js_sdk.js 在 app.js 之前 -->
    <script src="./js_sdk.js"></script>
    <script src="./app.js?v=3"></script>
    <script type="text/javascript">
    	var userInfo = null;
    	
        $(function() {
             // 1. 检测是否登陆,没有登录则登陆
             var code = getUrlParam("code");
             if(code==null){
                 wxLogin();
             }else{
                 userInfo = wxLogin2();
                 if(userInfo!=null){
                	 $("input[name=openid]").val(userInfo.openid);
                	 $("input[name=sys_mobile]").val(userInfo.sys_mobile);
                	 $("input[name=sys_name]").val(userInfo.sys_name);
                	 $("input[name=sys_code]").val(userInfo.sys_code);
                 }else{
                	 layer.msg("系统异常,请退出重试.");
                 }
             }
        });
    </script>
</head>
<body>
<section class="aui-flexView">
	
	<section class="aui-scrollView" style="padding-top: 10px;">
		
		<div class="aui-auto-form">
			<div class="aui-auto-box">
				<form id="myForm" action="" class="aui-auto-inp">
					<input name="openid" type="hidden">
					
					<div class="aui-flex">
						<label>手机号</label>
						<div class="aui-flex-box">
							<input type="text" name="sys_mobile" id="phone1" autocomplete="off" placeholder="请输入手机号码">
						</div>
					</div>
					<div class="aui-flex">
						<label>姓名</label>
						<div class="aui-flex-box">
							<input name="sys_name" autocomplete="off" type="text" placeholder="请输入姓名">
						</div>
					</div>
					<div class="aui-flex">
						<label>操作号</label>
						<div class="aui-flex-box">
							<input name="sys_code" autocomplete="off" type="text" placeholder="请输入员工操作号">
						</div>
					</div>
					<div class="aui-flex">
						<label>短信验证码</label>
						<div class="aui-flex-box">
							<input type="text" name="sms_code" id="code1" autocomplete="off" placeholder="请输入验证码">
							<input id="btnSendCode1" type="button" class="btn btn-default" value="获取验证码" onClick="sendMessage1()" />
						</div>
					</div>
					<button class="aui-apply-btn" type="button" onClick="binding()">确认绑定</button>

				</form>
			</div>
		</div>

	</section>
</section>
</body>
<script type="text/javascript">
	var phoneReg = /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/;
	var count = 60;
	var InterValObj1;
	var curCount1;
	function sendMessage1() {
		curCount1 = count;
		var phone = $('#phone1').val();
		if (!phoneReg.test(phone)) {
			layer.msg(" 请输入有效的手机号码");
			return false;
		}
		sendCode(phone);
		$("#btnSendCode1").attr("disabled", "true");
		$("#btnSendCode1").val( + curCount1 + "秒再获取");
		InterValObj1 = window.setInterval(SetRemainTime1, 1000);

	}
	function SetRemainTime1() {
		if (curCount1 == 0) {
			window.clearInterval(InterValObj1);
			$("#btnSendCode1").removeAttr("disabled");
			$("#btnSendCode1").val("重新发送");
		}
		else {
			curCount1--;
			$("#btnSendCode1").val( + curCount1 + "秒再获取");
		}
	}
	function sendCode(mobile){
		$.ajax({
	        type : "GET",
	        // async : false,
	        cache : false,
	        url : "/zweixin/sendSms?mobile="+mobile,
	        dateType : 'json',
	        success : function(result) {
	        	if(result.code == 200){
	        		layer.msg('短信已发送');
	        	}else{
	        		layer.msg('系统忙,请稍后再试!');
	        	}
	        },
	        error: function (xhr, textStatus, errorThrown) {
	    　　　　　　　　console.log(xhr);
	    　　　　　　　　console.log(textStatus);
	    　　　　　　　　console.log(errorThrown);
	    　　　　	} 
	    });
	}
</script>
<script type="text/javascript">
	layer.msg = function(tip){
		layer.open({
			time:3,
			skin:'msg',
			content:tip
		});
	}
	function binding(){
		if(userInfo==null){
			layer.msg("系统异常,请稍后再试.");
			return false;
		}else{
			$("input[name=openid]").val(userInfo.openid);
		}
		var phone = $('#phone1').val();
		if (!phoneReg.test(phone)) {
			layer.msg("请输入有效的手机号码");
			return false;
		}
		var sms_code = $("input[name=sms_code]").val();
		if(!sms_code){
			layer.msg("请输入短信验证码");
			return false;
		}
		var sys_name = $("input[name=sys_name]").val();
		if(!sys_name){
			layer.msg("请输入姓名");
			return false;
		}
		var sys_code = $("input[name=sys_code]").val();
		if(!sys_code){
			layer.msg("请输入工号");
			return false;
		}
		bindUser();
		
	}

	function bindUser(){
		var params = $("#myForm").serialize();
	    $.ajax({
	        type : "post",
	        async: false,
	        url : getServerHttp("/zweixin") + "/weixin/api/user/saveInfo",
	        data : params,
	        dateType : 'json',
	        success : function(result) {
	        	if(result.code == 200){
	        		console.log(result);
	        		layer.msg('保存成功!');
	        		WeixinJSBridge.call('closeWindow');
	        		// window.close();
	        	}else{
	        		layer.msg(result.message);
	        	}
	        }
	    });
	}
</script>

</html>
